package com.zhou.framework.util;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.asymmetric.RSA;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class UserUtil {
    public static String randomUsername(){
        String org = SettingUtil.getString("ORG", "random-user-name-hashset", RandomUtil.BASE_CHAR_NUMBER);
        String fmt = SettingUtil.getString("ORG", "random-user-name-format", "WX_%s%s%s%s%s%s%s%s%s%s");
        int cnt = 0,ind = -2;
        while ((ind = fmt.indexOf("%s",ind + 2)) != -1){
            cnt ++;
        }
        Object[] username = RandomUtil.randomString(org, cnt).split("");
        String format = String.format(fmt, username);

        return format;
    }
    public static String[] createKey(){
        RSA rsa = new RSA();
        // 获取公钥
        String pubKey = rsa.getPublicKeyBase64();
        // 获取私钥
        String priKey = rsa.getPrivateKeyBase64();
        return new String[]{pubKey,priKey};
    }
}
